<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Mailbox with some customizations as described in docs" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%@ include file="/include/main_include.jsp"%>
<style type="text/css">
#tt .tabs-wrap .tabs {
	width: 100%;
}
</style>

</head>
<body class="easyui-layout">
   <!-- 左部分 -->
	<div data-options="region:'west',title:'选择学校班级',split:true" style="width: 50%;">
		<div class="easyui-layout" data-options="fit:true,split:true,collapsible:true" >
				<c:if test="${user.role.equals('管理员')}">
				<div data-options="region:'west',split:true,collapsible:true" style="width:17%">
					<table id="city_table"></table>
				</div>
				<script>
				var city_table= $('#city_table').treegrid({  
					fitColumns: true,
					fit:true,
					nowrap:true,
					animate:true,
					nowrap: true,
				    url:'${path}/pkCity/cityList.do?id=0',
				    idField:'id',    
				    treeField:'text',    
				    columns:[[    
				        {title:'城市',field:'text',width:'100%'}  
				    ]],
					onClickRow:function( row){
						 
						school_table.datagrid('options').queryParams = {city:row.title,parentId:row.parentid};
						school_table.datagrid("reload");
					} 
				});  
				
				</script>
				</c:if>
				
				<div data-options="region:'center',split:true" style="width:34%">
					<table id="school_table"></table>
				</div>
				<div data-options="region:'east',split:true,collapsible:true" style="width:33%">
				<div class="easyui-layout" data-options="fit:true">
					<div data-options="region:'north',border:false" style="height:42px;">
						<div class="grsun-toolbar">
								<button type="button" id="addClass" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
									<i class="ace-icon fa fa-plus blue bigger"></i>
									增加
								</button>
								<button type="button" id="editClass" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
									<i class="ace-icon fa fa-edit orange bigger"></i>
									修改
								</button>
								<button type="button" id="delClass" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
									<i class="ace-icon fa fa-remove red bigger"></i>
									删除
								</button>
						</div>
					</div>
					<div data-options="region:'center'">
						<table id="class_table"></table>
					</div>
				</div>
				</div>
			</div>
	</div>
	<div data-options="region:'center',border:true">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'north',border:false" style="height:42px;">
				<div class="grsun-toolbar">
						<button type="button" id="edit" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
							<i class="ace-icon fa fa-edit orange bigger"></i>
							修改
						</button>
						<button type="button" id="unbind" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
							<i class="ace-icon fa fa-edit orange bigger"></i>
							解绑
						</button>
						<button type="button" id="del" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
							<i class="ace-icon fa fa-remove red bigger"></i>
							删除
						</button>
						<button type="button" id="search" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
							<i class="ace-icon fa fa-search green bigger"></i>
							查询
						</button>
				</div>
			</div>
			<div data-options="region:'center'">
				<table id="data_table"></table>
			</div>
		</div>
	</div>  
	
	
	<script type="text/javascript">
		var searchParams;
		$(function(){
			//添加按钮事件
			$('#add').on('click', function() {
				openedit('');
			});
			//修改按钮事件
			$('#edit').on('click', function() {
				var node = dataTable.datagrid('getSelected');
				if (node) {
					openedit(node.userId);
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			//删除按钮事件
			$('#del').on('click', function() {
				del();
			});
			//查询按钮事件
			$('#search').on('click', function() {
				opensearch();
			});
			// 
			$('#unbind').on('click', function() {
				unbind();
			});
			
			//添加按钮事件
			$('#addClass').on('click', function() {
				openeditClass('');
			});
			//修改按钮事件
			$('#editClass').on('click', function() {
				var node = classTable.datagrid('getSelected');
				if (node) {
					openeditClass(node.classId);
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			//删除按钮事件
			$('#delClass').on('click', function() {
				delClass();
			});
			 
		});
		
		
		
		//Table表格数据源
		var school_table = $('#school_table').datagrid(BasicData.createDatagrid({  
			url : rootpath + '/pkSchool/schoolList.do?status=1',
			frozenColumns:[[
				{field:'ck',checkbox:true},
				{title:'schoolId',field:'schoolId',hidden:true}
			]],
			columns:[[
				{field:'school',title:'学校',width:'40%',sortable:true,align:'center'},
				{field:'province',title:'省',width:'20%',sortable:true,align:'center'},
				{field:'city',title:'市',width:'20%',sortable:true,align:'center'},
				{field:'county',title:'县',width:'20%',sortable:true,align:'center'} 
			]],
			onClickRow:function(rowIndex, row){
				classTable.datagrid('options').queryParams = {schoolId:row.schoolId};
				classTable.datagrid("reload");
			}
		}));  
		//Table表格数据源
		var classTable = $('#class_table').datagrid(BasicData.createDatagrid({  
			url : rootpath + '/pkClass/classList.do',
			frozenColumns:[[
				{field:'ck',checkbox:true},
				{title:'classId',field:'classId',hidden:true}
			]],
			columns:[[
				{field:'gradeName',title:'年级',width:'50%',sortable:true,align:'center'},
				{field:'className',title:'班级',width:'50%',sortable:true,align:'center'}  
			]],
			onClickRow:function(rowIndex, row){
				dataTable.datagrid('options').queryParams = {schoolId:row.schoolId,gradeName:row.gradeName,className:row.className};
				dataTable.datagrid("reload");
			}
		}));  
		//Table表格数据源
		var dataTable = $('#data_table').datagrid(BasicData.createDatagrid({  
			url : rootpath + '/pkUser/list.do',
			frozenColumns:[[
				{field:'ck',checkbox:true},
				{title:'userId',field:'userId',hidden:true}
			]],
			columns:[[
				{field:'name',title:'姓名',width:'10%',sortable:true,align:'center'},
				{field:'phone',title:'电话',width:'10%',sortable:true,align:'center'}, 
				{field:'unionId',title:'openId',width:'10%',sortable:true,align:'center'}, 
				{field:'className',title:'班级',width:'10%',sortable:true,align:'center'},
				{field:'gradeName',title:'年级',width:'10%',sortable:true,align:'center'}, 
				{field:'no',title:'学号',width:'10%',sortable:true,align:'center'} 
			]] ,
			onClickRow:function(rowIndex, row){
			}
		}));  
		//打开查询窗体
		function opensearch(){
			layer.open({
				title : '查询条件',
				type : 2,
				btn : ['查询','重置'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					searchParams = iframeWin.$("#searchForm").serialize();
					var newparam = iframeWin.$("#searchForm").serializeJSON();
					$.extend(newparam,dataTable.queryParams);
					$('#data_table').datagrid('load',newparam);
					layer.close(index);
				},
				btn2 : function(index, layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.$("#searchForm").form("clear");
					return false;
				},
				area : [ '50%', '50%' ],
				content : rootpath + '/pkUser/toSearch.do?'+searchParams
			});
		}
		//编辑打开窗体
		function openedit(userId){
			layer.open({
				title : '信息',
				type : 2,
				btn : ['保存','关闭'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.$("#dataForm").submit();
				},
				btn2 : function(index, layero) {
				},
				area : [ '50%', '50%' ],
				content : rootpath + '/pkUser/toEdit.do?role=student&userId='+userId
			});
		}
		//删除
		function del() {
			var node = dataTable.datagrid('getSelected');
			if (node) {
				layer.confirm('您确定要删除吗？', {
					btn : [ '确定', '取消' ]
				}, function(index, layero) {
				    layer.close(index);
					$.uitools.showLoading();//打开处理中遮罩层
					$.ajax({
						cache : true,
						type : "POST",
						url : rootpath + '/pkUser/delete.do',
						data : {
							userId : node.userId
						},
						error : function(request) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							layer.msg('系统异常！', {
								icon : 2,
								time : 1000
							})
						},
						success : function(data) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							if (data.code==0){
								layer.msg('删除成功！', {
									icon : 1,
									time : 1000
								}, function() {
									dataTable.datagrid('reload');
								})
							}else {
								layer.msg('删除异常！', {
									icon : 2,
									time : 1000
								})
							}
						}
					});
				}, function() {
				});
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}
		//解绑
		function unbind() {
			var node = dataTable.datagrid('getSelected');
			if (node) {
				layer.confirm('您确定要解绑吗？', {
					btn : [ '确定', '取消' ]
				}, function(index, layero) {
				    layer.close(index);
					$.uitools.showLoading();//打开处理中遮罩层
					$.ajax({
						cache : true,
						type : "POST",
						url : rootpath + '/pkUser/unBindInfo.do',
						data : {
							userId : node.userId
						},
						error : function(request) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							layer.msg('系统异常！', {
								icon : 2,
								time : 1000
							})
						},
						success : function(data) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							if (data.code==0){
								layer.msg('删除成功！', {
									icon : 1,
									time : 1000
								}, function() {
									dataTable.datagrid('reload');
								})
							}else {
								layer.msg('删除异常！', {
									icon : 2,
									time : 1000
								})
							}
						}
					});
				}, function() {
				});
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}
		//编辑打开窗体
		function openeditClass(classId){
			layer.open({
				title : '信息',
				type : 2,
				btn : ['保存','关闭'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.$("#dataForm").submit();
				},
				btn2 : function(index, layero) {
				},
				area : [ '50%', '50%' ],
				content : rootpath + '/pkClass/toEdit.do?classId='+classId
			});
		}
		//删除
		function delClass() {
			var node = classTable.datagrid('getSelected');
			if (node) {
				layer.confirm('您确定要删除吗？', {
					btn : [ '确定', '取消' ]
				}, function(index, layero) {
				    layer.close(index);
					$.uitools.showLoading();//打开处理中遮罩层
					$.ajax({
						cache : true,
						type : "POST",
						url : rootpath + '/pkClass/delete.do',
						data : {
							classId : node.classId
						},
						error : function(request) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							layer.msg('系统异常！', {
								icon : 2,
								time : 1000
							})
						},
						success : function(data) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							if (data.code==0){
								layer.msg('删除成功！', {
									icon : 1,
									time : 1000
								}, function() {
									classTable.datagrid('reload');
								})
							}else {
								layer.msg('删除异常！', {
									icon : 2,
									time : 1000
								})
							}
						}
					});
				}, function() {
				});
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}
	</script>
</body>
</html>